package com.mercury.pattern._03_prototype._003_deep;

public class Center {
    /**
     * 深拷贝测试
     * @param args
     */
    public static void main(String[] args) {
        //方式1：利用clone
        System.out.println("~~方式2： 利用clone");
        Wool wool = new Wool(true, 12);
        Sheep sheep = new Sheep("tom", 10, "白色", wool);

        Sheep clone1 = (Sheep)sheep.clone();
        Sheep clone2 = (Sheep)sheep.clone();
        Sheep clone3 = (Sheep)sheep.clone();

        System.out.println(sheep.hashCode() == clone1.hashCode());

        System.out.println(sheep.getWool().hashCode() == clone1.getWool().hashCode());

        System.out.println("~~方式2： 利用序列化");
        Wool wool2 = new Wool(true, 12);
        Sheep sheep2 = new Sheep("tom", 10, "白色", wool2);

        Sheep c1 = (Sheep) sheep2.cloneObj();
        Sheep c2 = (Sheep) sheep2.cloneObj();
        Sheep c3 = (Sheep) sheep2.cloneObj();

        System.out.println(sheep2.hashCode() == c1.hashCode());

        System.out.println(sheep2.getWool().hashCode() == c1.getWool().hashCode());
    }
}
